-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get block notifications API #3781
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one overall.
pkg/services/rpcsrv/server_test.go
Outdated
params: `["` + genesisBlockHash + `", {"contract":"` + testContractHashLE + `", "name":"Transfer"}]`, | ||
result: func(e *executor) any { return []state.ContainedNotificationEvent{} }, | ||
check: func(t *testing.T, e *executor, acc any) { | ||
res, ok := acc.([]state.ContainedNotificationEvent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check for expected contents as well.
RPC client needs to be updated to support this as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A useful extension.
Please, ensure testing jobs are passing. Currently, unit-tests, project linter and DCO checks are failing. |
Hey guys, got some busy days ahead. I'll come back to this in one or two weeks max. Sorry for the delay |
c1849a5
to
dee62f4
Compare
dee62f4
to
cb76197
Compare
PR Updated. Changes:
Still pending:
About trigger filters: I don't know/don't have an opinion. |
return nil | ||
} | ||
|
||
func (b *TrimmedBlock) ToStackItem() stackitem.Item { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, remove it. We're only interested in proper deserialization from bytes.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3781 +/- ##
==========================================
- Coverage 83.14% 82.99% -0.16%
==========================================
Files 335 335
Lines 46896 47056 +160
==========================================
+ Hits 38994 39054 +60
- Misses 6310 6399 +89
- Partials 1592 1603 +11 ☔ View full report in Codecov by Sentry. |
@@ -248,6 +248,10 @@ block. It can be removed in future versions, but at the moment you can use it | |||
to see how much GAS is burned with a particular block (because system fees are | |||
burned). | |||
|
|||
#### `getblocknotifications` call | |||
|
|||
This method returns notifications from a block organized by trigger type. Supports filtering by contract and event name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, preserve common line width (~80 symbols).
@@ -221,7 +235,6 @@ func (b *Block) GetExpectedBlockSizeWithoutTransactions(txCount int) int { | |||
return size | |||
} | |||
|
|||
// ToStackItem converts Block to stackitem.Item. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless change.
type auxTrimmedBlockOut struct { | ||
TxHashes []util.Uint256 `json:"tx"` | ||
} | ||
|
||
// auxTrimmedBlockIn is used for JSON i/o. | ||
type auxTrimmedBlockIn struct { | ||
TxHashes []json.RawMessage `json:"tx"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON marshallers are not needed for this structure. DecodeBinary is enough for our purposes.
return block, br.Err | ||
} | ||
|
||
func (b TrimmedBlock) MarshalJSON() ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also should be removed, why do we need this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first, I considered adding a get trimmed block endpoint. I also had some issues to debug the RPC endpoints (it doesn't stop on the debugger). I had an error that I didn't know where it was coming from. Later I realized that it was due to the notification object serialization, not the block. The same for the 'toStackItem'. I didn't know if that was being used (now I know).
I also got confused because the tests 'were passing', when in practice, they weren't. I 'suspected' that this was related to some inner serilization / deserialization that I wasn't aware of. That's why I included these methods. I'll remove this and other parts that aren't being used.
return nil | ||
} | ||
|
||
func (b *TrimmedBlock) ToStackItem() stackitem.Item { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, remove it. We're only interested in proper deserialization from bytes.
@@ -18,3 +24,46 @@ func checkInt32(i int) error { | |||
} | |||
return nil | |||
} | |||
|
|||
func (c notificationComparatorFilter) EventID() neorpc.EventID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All exported methods require a comment.
@@ -18,3 +24,46 @@ func checkInt32(i int) error { | |||
} | |||
return nil | |||
} | |||
|
|||
func (c notificationComparatorFilter) EventID() neorpc.EventID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're trying to avoid util.go
files as much as possible. Let's create a dedicated file for these structures and name this file accordingly.
@@ -18,3 +24,46 @@ func checkInt32(i int) error { | |||
} | |||
return nil | |||
} | |||
|
|||
func (c notificationComparatorFilter) EventID() neorpc.EventID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/notificationComparatorFilter/notificationEventComparator
@@ -18,3 +24,46 @@ func checkInt32(i int) error { | |||
} | |||
return nil | |||
} | |||
|
|||
func (c notificationComparatorFilter) EventID() neorpc.EventID { | |||
return c.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.id
field is not needed, remove it. notificatoinEventComparator
works only with ContainedNotificatoinEvent
, hence you may return neorpc.NotificationEventID
here.
Container: container, | ||
NotificationEvent: evt, | ||
} | ||
if filter == nil || rpcevent.Matches(¬ificationComparatorFilter{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter == nil
check is excessive. rpcevent.Matche
perfectly handle this case.
Seems that we don't need it for now, so nothing should be done wrt this question. |
Please, format commits according to https://github.com/nspcc-dev/.github/blob/master/git.md#commits. See https://github.com/nspcc-dev/neo-go/pull/3787/commits for example. Also, please ensure your commits have valid signed-off-by signature. |
@@ -439,6 +439,21 @@ func (dao *Simple) getBlock(key []byte) (*block.Block, error) { | |||
return block, nil | |||
} | |||
|
|||
// GetTrimmedBlock returns a block with only the header and transaction hashes. | |||
func (dao *Simple) GetTrimmedBlock(hash util.Uint256) (*block.TrimmedBlock, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need it? GetBlock()
already does the same thing at the DAO level.
Closes #3779.
It works but I don't know if this is the best way to do it.